While the 190 per 10 seconds (for Pro/Ent) rate limit on API calls for Hubspot is often sufficient, there may be occasions where you need to have more API calls in a short time window.

However— Worth noting the limit of 190 per 10 seconds is per private app. So— if you have some sort of need to get more per second, you can get around this by creating separate private apps with the exact same scope. There is a limit of 20 private apps per account— However in the case I was working to solve, our client was only using 2 private apps, so creating a total of 5 more apps to speed things up was not an issue.

In this example, I needed custom code that was using an API call to fire faster. So the first step was separating out the total records that would need to be run through into 5 groups. A single piece of custom-code assigned all records in the flow a random number 1 to 10

import random

def main(event):
    random_number = random.randint(1, 10)
    return {
        "outputFields": {
            "random_number": random_number
        }
    }

Saved that output to a property “Random Group” then moved on to splitting these into separate branches based on the value. Since the random numbers were 1 to 10, and I wanted it split a total of 5 ways, each group had 2 numbers assigned to it (1 and 2, 3 and 4, etc.).

Each one of these pieces of custom code that actually calls the API then is completely identical except that the private app token is unique to each one. So records going through this workflow will split based on the random grouping.

Then, leveraging the new beta for throttling rate limits of custom code actions, I was able to put a custom rate limit on each of these steps. In theory 190 calls per 10 second would be the rate limit needed, however in testing I noticed that I was still getting some 429 errors. So, instead I adjusted down a bit from the max, and I also limited by 1 second instead of 10 seconds. After some experimenting, 14 per 1 second (so in theory 140 per 10 seconds) seemed to be a place where there were no errors yet still goes pretty quickly.

This exact same technique could be used with other modes of API integration via private apps as well. A python script could be setup to do the exact same thing, just limiting to each access token based on timing and simply rotating through different access keys.

Nothing too fancy here— but solved a major issue for the client. Instead of this weekly process taking almost half a day, the whole thing wraps in a matter of hours after splitting this amongst several private apps.

Related posts

Leave a Comment